package com.vdong.common.oauth.common.authorize.redirect;

import java.util.List;

/**
 * @author 刀锋
 * @date : Create in 11:08 2018/7/2
 * @description:
 */
public class SimpleRedirectDecider implements RedirectDecider {
    private RedirectMatcher redirectMatcher;

    public SimpleRedirectDecider(RedirectMatcher redirectMatcher) {
        this.redirectMatcher = redirectMatcher;
    }

    @Override
    public String decideRedirectUrl(List<RedirectUrlAndPattern> patterns, String sourceUrl) {
        for (int i = 0; i < patterns.size(); i++) {
            RedirectUrlAndPattern redirectUrlAndPattern = patterns.get(i);
            if(redirectMatcher.isMatch(redirectUrlAndPattern, sourceUrl)){
                return redirectUrlAndPattern.getUrl();
            }
        }
        return null;
    }
}
